#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct Node
{
	queue<long long> a,b;
};
long long n,cnt=0,ans=0,ch[1000005][2],dep[1000005],sum[1000005];
string s;
priority_queue<long long> q;
void insert(string s)
{
	long long u=0;
	for(long long i=0;i<(long long)s.size();i++)
	{
		if(!ch[u][s[i]-'0'])
		{
			cnt++;
			ch[u][s[i]-'0']=cnt;
			dep[ch[u][s[i]-'0']]=dep[u]+1;
		}
		u=ch[u][s[i]-'0'];
	}
	sum[u]++;
}
Node dfs(long long u,long long v)
{
	priority_queue<pair<long long,long long>,vector<pair<long long,long long> >,greater<pair<long long,long long> > > q;
	if(ch[u][0])
	{
		Node x=dfs(ch[u][0],v+sum[u]);
		while(!x.a.empty()&&!x.b.empty())
		{
			q.push({x.a.front(),x.b.front()});
			x.a.pop(),x.b.pop();
		}
	}
	if(ch[u][1])
	{
		Node x=dfs(ch[u][1],v+sum[u]);
		while(!x.a.empty()&&!x.b.empty())
		{
			q.push({x.a.front(),x.b.front()});
			x.a.pop(),x.b.pop();
		}
	}
	if(!ch[u][0]&&!ch[u][1])
	{
		sum[u]--;
		q.push({dep[u]+2,0});
	}
	else if(!ch[u][0]||!ch[u][1])
	{
		q.push({dep[u]+1,1});
	}
	for(long long i=1;i<=sum[u];i++)
	{
		long long x=q.top().first,y=q.top().second;
		ans+=abs(x-dep[u]); 
		if(y==0)
		{
			q.push({x+1,0}),q.push({x+1,0}); 
		}
		else
		{
			q.push({x+2,0});
		}
	}
	queue<long long> a,b; 
	while(!q.empty())
	{
		a.push(q.top().first),b.push(q.top().second);
		q.pop();
	}
	return Node{a,b};
}
int main()
{
	freopen("id.in","r",stdin);
	freopen("id.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(long long i=1;i<=n;i++)
	{
		cin>>s;
		insert(s);
	}
	dfs(0,0);
	cout<<ans<<endl;
	return 0;
}
